package org.ggn.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

@SuppressWarnings("deprecation")
public class HibernateUtil {
	private final static SessionFactory FACTORY = buildSessionFACTORY();
	
	public static SessionFactory buildSessionFACTORY(){
		Configuration cfg = new Configuration().configure();
		ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
		SessionFactory FACTORY = cfg.buildSessionFactory(serviceRegistry);
		return FACTORY;
	}
	public static SessionFactory getSessionFactory(){
		return FACTORY;
	}
	public static Session openSession() {
		return FACTORY.openSession();
	}
	public static void close(Session session){
		session.close();
	}
}
